import App from './App'
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'


import {authorWechat} from "@/utils/api/api.js";
import config from "@/utils/config.js";
let {photo_cdn} = config.baseUrl;
// 引入全局uView
import uView from 'uview-ui'
Vue.use(uView);

import store from './store'
import G_show_modal from '@/components/G_show_modal/g_show_modal.js';
Vue.use(G_show_modal);

import login from "@/components/login/login.vue"
Vue.component('login', login)

import empty from "@/components/empty.vue";
Vue.component('empty', empty)
const msg = (title, duration=1500, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
Vue.prototype.$api = {msg};// json, prePage
Vue.prototype.$store = store;//
Vue.prototype.$themecolor  =  '#c02e36';//主题色

// #ifdef MP-WEIXIN
Vue.prototype.$getweixin = ()=> {
	return new Promise((ret,rej)=>{
		
		wx.getUserProfile({ //获取用户信息
			lang: 'zh_CN',
			desc: '用于完善会员资料',
			success: (res) => {
				console.info("res",res);
				wx.login({
					provider: 'weixin',
					success: (loginRes)=> {
						//loginRes中有code，拿着code再请求自己服务器以获取openid
						authorWechat({
							code:loginRes.code
						}).then((res)=>{
							ret(res);
						})
					},
					fail:(err)=> {
						rej(err);
					}
				});
			},
			fail:(err)=> {
				rej(err);
			}
		})
	})
}
// #endif


import {timestampToTime,formatMsgTime} from "@/utils/yicode.js";
Vue.filter("parsetime",(val)=>{
	return timestampToTime(val);
});

//解析多久时间前 传的是时间戳
Vue.filter("formatMsgTime",(val)=>{
	return formatMsgTime(val);
})
Vue.filter("format_pu_type",(types)=>{
	if(types==1){
		return "氏家谱";
	}else if(types==2){
		return "氏族谱";
	}else if(types==3){
		return "氏宗谱";
	}else{
		return "";
	}
});
//判断图片路径
Vue.filter("imgtell",(val)=>{
	if(val.indexOf("https")!=-1){
		return val;
	}else{
		return photo_cdn+val;
	}
})
const app = new Vue({
  ...App
})

import httpInterceptor from '@/common/http.interceptor.js'
Vue.use(httpInterceptor, app)

import webSocket from '@/common/websocket.js'
webSocket.ws.that = app
Vue.prototype.ws = webSocket.ws

app.$mount()
